package com.cloudfun.campusshare.device.protocol.command;

import com.cloudfun.campusshare.entity.DeviceEntity;
import com.cloudfun.campusshare.repo.DeviceEntityRepo;
import lombok.extern.slf4j.Slf4j;

/**
 * @author wangxiyuan
 * @description 校验设备状态任务
 * @createDate 2021/6/7 11:12
 **/
@Slf4j
public class CheckDeviceStatus implements Runnable{
    private DeviceEntityRepo deviceEntityRepo;

    private String imei;

    public CheckDeviceStatus(DeviceEntityRepo deviceEntityRepo,String imei){
        this.deviceEntityRepo = deviceEntityRepo;
        this.imei = imei;
    }

    @Override
    public void run() {
        DeviceEntity deviceEntity = deviceEntityRepo.findByImei(imei);
        if(deviceEntity != null && !deviceEntity.getOnline()){
            log.error("{}设备显示离线，但设备仍在接收消息，更新设备状态为上线",imei);
            deviceEntityRepo.updateDeviceOnline(imei);
        }
    }
}
